package com.example.jinbo.helloword;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * Created by gzpc on 2015/12/17.
 */
public class Adapter extends BaseAdapter {
    private LayoutInflater mInflater;
    public TextView item;
    public String[] strs;


    public Adapter(Context context,String []strs) {
        this.mInflater = LayoutInflater.from(context);
        this.strs=strs;
    }

    public int getCount() {
        // TODO Auto-generated method stub
        return strs.length;
    }
    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return strs[arg0];
    }
    public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return arg0;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.list_item, null);
            item = (TextView) convertView.findViewById(R.id.item);

            convertView.setTag(item);
        } else {
            item = (TextView) convertView.getTag();
        }

        item.setText(strs[position]);
        if (position == selectItem) {
            convertView.setBackgroundColor(Color.CYAN);
        }
        else {
            convertView.setBackgroundColor(Color.TRANSPARENT);
        }

        //convertView.getBackground().setAlpha(80);

        return convertView;
    }
    public  void setSelectItem(int selectItem) {
        this.selectItem = selectItem;
        notifyDataSetChanged();
    }
    private int  selectItem=-1;
}

